package com.jiutian.admin.dao.impl;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.Query;
import com.jiutian.admin.dao.AdminDao;
import com.jiutian.factory.HibernateSessionFactory;
import com.jiutian.hotel.pojo.HotelDetailData;
import com.jiutian.hotel.pojo.HotelInfoData;

public class AdminDaoImpl implements AdminDao{
    public boolean saveHotelinfo(HotelInfoData hotelinfo){
        Session session=null;
        Transaction tx=null;
        boolean result=false;
        try{
            session=HibernateSessionFactory.getSession();
            tx=session.beginTransaction();
            session.saveOrUpdate(hotelinfo);
            tx.commit();
            result = true;
        } catch (Exception ex) {
            ex.printStackTrace();
            result=false;
            tx.rollback();
        } finally {
            session.close();
        }
        return result;
    }
    public boolean saveHoteldetail(HotelDetailData hoteldetail){
        Session session=null;
        Transaction tx=null;
        boolean result=false;
        try{
            session=HibernateSessionFactory.getSession();
            tx=session.beginTransaction();
            session.saveOrUpdate(hoteldetail);
            tx.commit();
            result = true;
        } catch (Exception ex) {
            ex.printStackTrace();
            result=false;
            tx.rollback();
        } finally {
            session.close();
        }
        return result;
    }
    public HotelInfoData getHotelinfo(String hotelid){
        Session session=null;
        try{
            session=HibernateSessionFactory.getSession();
            Query query=session.createQuery("from HotelInfoData p where p.hotelid= :hotelid");
            return (HotelInfoData)query.setString("hotelid", hotelid).uniqueResult();
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        } finally {
            session.close();
        }
    }
    public HotelDetailData getHoteldetail(String hotelid){
        Session session=null;
        try{
            session=HibernateSessionFactory.getSession();
            Query query=session.createQuery("from HotelDetailData p where p.hotelid= :hotelid");
            return (HotelDetailData)query.setString("hotelid", hotelid).uniqueResult();
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        } finally {
            session.close();
        }
    }
}
